﻿using System;
using System.Collections.Generic;
using System.Text;
using WebQ.Core;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace WebQ.Visualizers {
	public class WebQTextBoxVisualizer : WebQVisualizer {
		public WebQTextBoxVisualizer ( WebQIdGenerator generator, WebQVisualizerConfiguration conf )
			: base ( generator, conf ) {

		}

		protected override List<System.Web.UI.Control> CreateChildControls ( WebQQAItem entity, WebQIdGenerator generator, WebQVisualizerConfiguration conf ) {
			List<Control> ctrls = new List<Control> ();
			generator.Reset ();

			Label question = new Label ();
			question.Text = entity.QuestionString;

			ctrls.Add ( question );

			ctrls.Add ( new LiteralControl ( "<br />" ) );

			TextBox answer = new TextBox ();
			answer.ID = generator.GetNext ();

			ctrls.Add ( answer );

			ctrls.Add ( new LiteralControl ( "<br />" ) );

			return ctrls;
		}

		protected override void SetAnswers ( WebQQAItem entity, WebQIdGenerator generator, WebQVisualizerConfiguration conf, Dictionary<string, string> postbackedValues ) {
			generator.Reset ();

			String answerId = generator.GetNext ();

			entity.Answers.Clear ();
			if ( postbackedValues.ContainsKey ( answerId ) ) {
				entity.Answers.Add ( postbackedValues[answerId] );
			}
		}
	}
}
